package com.pad.pcbuilder;

import java.util.ArrayList;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Consultas {
	
	private String nombre, socket;
	private int precio;
	
	public Consultas(){}
	
	public ArrayList<Componente> verCPUS(Connection conexion){
		
		try{
			String sql = "SELECT * FROM `cpu`";
			PreparedStatement ps = conexion.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<Componente> comps = new ArrayList<Componente>();
			while (rs.next()){
				this.nombre = rs.getString("text_cpu");
				this.socket = rs.getString("id_socket");
				this.precio = rs.getInt("precio_cpu");
				Componente comp = new Componente(this.precio, this.nombre, this.socket);
				comps.add(comp);
			}
			ps.close();
					
			return comps;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public ArrayList<Componente> verCajas(Connection conexion){
		
		try{
			String sql = "SELECT * FROM `caja`";
			PreparedStatement ps = conexion.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<Componente> comps = new ArrayList<Componente>();
			while (rs.next()){
				this.nombre = rs.getString("text_caja");
				this.precio = rs.getInt("precio_caja");
				Componente comp = new Componente(this.precio, this.nombre, "");
				comps.add(comp);
			}
			ps.close();
					
			return comps;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public ArrayList<Componente> verDisipadores(Connection conexion){
		
		try{
			String sql = "SELECT * FROM `disipador`";
			PreparedStatement ps = conexion.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<Componente> comps = new ArrayList<Componente>();
			while (rs.next()){
				this.nombre = rs.getString("text_disipador");
				this.precio = rs.getInt("precio_disip");
				Componente comp = new Componente(this.precio, this.nombre, "");
				comps.add(comp);
			}
			ps.close();
					
			return comps;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public ArrayList<Componente> verFuentes(Connection conexion){
		
		try{
			String sql = "SELECT * FROM `fuente`";
			PreparedStatement ps = conexion.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<Componente> comps = new ArrayList<Componente>();
			while (rs.next()){
				this.nombre = rs.getString("text_fuente");
				this.precio = rs.getInt("precio_fuente");
				Componente comp = new Componente(this.precio, this.nombre, "");
				comps.add(comp);
			}
			ps.close();
					
			return comps;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public ArrayList<Componente> verGPUS(Connection conexion){
		
		try{
			String sql = "SELECT * FROM `gpu`";
			PreparedStatement ps = conexion.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<Componente> comps = new ArrayList<Componente>();
			while (rs.next()){
				this.nombre = rs.getString("text_gpu");
				this.precio = rs.getInt("precio_gpu");
				Componente comp = new Componente(this.precio, this.nombre, "");
				comps.add(comp);
			}
			ps.close();
					
			return comps;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public ArrayList<Componente> verHDDs(Connection conexion){
		
		try{
			String sql = "SELECT * FROM `hdd`";
			PreparedStatement ps = conexion.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<Componente> comps = new ArrayList<Componente>();
			while (rs.next()){
				this.nombre = rs.getString("text_hdd");
				this.precio = rs.getInt("precio_hdd");
				Componente comp = new Componente(this.precio, this.nombre, "");
				comps.add(comp);
			}
			ps.close();
					
			return comps;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public ArrayList<Componente> verLectores(Connection conexion){
		
		try{
			String sql = "SELECT * FROM `lector`";
			PreparedStatement ps = conexion.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<Componente> comps = new ArrayList<Componente>();
			while (rs.next()){
				this.nombre = rs.getString("text_lector");
				this.precio = rs.getInt("precio_lector");
				Componente comp = new Componente(this.precio, this.nombre, "");
				comps.add(comp);
			}
			ps.close();
					
			return comps;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public ArrayList<Componente> verPlacas(Connection conexion){
		
		try{
			String sql = "SELECT * FROM `placabase`";
			PreparedStatement ps = conexion.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<Componente> comps = new ArrayList<Componente>();
			while (rs.next()){
				this.nombre = rs.getString("text_placaBase");
				this.socket = rs.getString("id_socket");
				this.precio = rs.getInt("precio_placa");
				Componente comp = new Componente(this.precio, this.nombre, this.socket);
				comps.add(comp);
			}
			ps.close();
					
			return comps;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public ArrayList<Componente> verRAM(Connection conexion){
		
		try{
			String sql = "SELECT * FROM `ram`";
			PreparedStatement ps = conexion.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<Componente> comps = new ArrayList<Componente>();
			while (rs.next()){
				this.nombre = rs.getString("text_ram");
				this.precio = rs.getInt("precio_ram");
				Componente comp = new Componente(this.precio, this.nombre, "");
				comps.add(comp);
			}
			ps.close();
					
			return comps;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public ArrayList<Componente> verSockets(Connection conexion){
		
		try{
			String sql = "SELECT * FROM `socket`";
			PreparedStatement ps = conexion.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<Componente> comps = new ArrayList<Componente>();
			while (rs.next()){
				this.nombre = rs.getString("nom_socket");
				this.socket = rs.getString("id_socket");
				Componente comp = new Componente(0, this.nombre, this.socket);
				comps.add(comp);
			}
			ps.close();
					
			return comps;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}


}
